package org.hackystat.devcathlon.ui.page.teams.manage;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.hackystat.devcathlon.engine.team.TeamManager;
import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.DevcathlonBasePage;
import org.hackystat.devcathlon.ui.page.teams.TeamsSession;

/**
 * Implements the Teams Manage Delete page, which asks for confirmation before deleting. 
 * the current user. 
 * @author John Ly
 */
public class TeamsManageDeletePage extends DevcathlonBasePage {
  /** Support serialization. */
  private static final long serialVersionUID = 1L;
  
  /**
   * Creates the TeamsManageDelete page.    
   */
  public TeamsManageDeletePage () {
    // Set the body class attribute to section-2 so that the menubar is correct.
    add(new WebMarkupContainer("body") { 
      private static final long serialVersionUID = 1L;
      @Override
      public boolean isTransparentResolver() { 
        return true; 
        } 
      @Override
      protected void onComponentTag(ComponentTag tag) { 
        tag.put("class","section-2"); 
        }
    }
    );     
    
    // Make the tab corresponding to this page bold.
    get("TeamsManageLink").add(new SimpleAttributeModifier("class", "selected"));
    
    TeamsSession teamSession = DevcathlonSession.get().getTeamsSession();
    
    // Create the form
    Form form = new Form("DeleteTeamForm") {
      private static final long serialVersionUID = 1L;
      
      @Override
      public void onSubmit() {       
        String teamName = DevcathlonSession.get().getTeamsSession().getSelectedTeam();
        TeamManager.getInstance().deleteTeam(teamName);
        setResponsePage(new TeamsManagePage());
      }      
    };
    
    // Add label specifying selected team
    form.add(new Label("TeamNameLabel", teamSession.getSelectedTeam()));
    
    // Add cancel button to form.
    Button cancel = new Button("CancelButton") {
      private static final long serialVersionUID = 1L;
      
      @Override
      public void onSubmit() {
        setResponsePage(new TeamsManagePage());
      }      
    };
    cancel.setDefaultFormProcessing(false);
    form.add(cancel);
    
    add(form);    
  }

}